using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Ras2ClassLib.Common.Data;

namespace Ras2ClassLib
{
	public class Flytjandi : IDataItem
	{
		private int m_nID;
        private String m_strName;
        private String m_strDescription;
        private String m_strPicture;
        private String m_strURL;
        
		#region Properties
		public int ID
        {
            get { return m_nID; }
            set { m_nID = value; }
        }

        public String Name
        {
            get { return m_strName; }
            set { m_strName = value; }
        }
        

        public String Description
        {
            get { return m_strDescription; }
            set { m_strDescription = value; }
        }

        public String Picture
        {
            get { return m_strPicture; }
            set { m_strPicture = value; }
        }

        public String URL
        {
            get { return m_strURL; }
            set { m_strURL = value; }
        }
		#endregion

		#region Constructors
		public Flytjandi()
		{

		}

		public Flytjandi(String name)
		{
			m_strName = name;
		}

		#endregion

		#region Overridden functions
		public override String ToString()
		{
			return m_strName;
		}
		#endregion

		#region IDataList implementation
		public void Load( IDataReader reader )
		{
			m_nID = Convert.ToInt32(reader["FlytjandiID"]);
			m_strName = reader["FlytjandiNafn"].ToString();
			m_strDescription = reader["FlytjandiLysing"].ToString();
			m_strPicture = reader["FlytjandiMynd"].ToString();
			m_strURL = reader["FlytjandiURL"].ToString();
		}
		#endregion

		public TableDescription GetTable( )
		{
			ColumnDescription[] columns = 
			{
				new ColumnDescription( "FlytjandiID", this.ID, DbType.Int32, true ),
				new ColumnDescription( "FlytjandiNafn", this.Name, DbType.String ),
				new ColumnDescription( "FlytjandiLysing", this.Description, DbType.String ),
				new ColumnDescription( "FlytjandiMynd", this.Picture, DbType.String ),
				new ColumnDescription( "FlytjandiURL", this.URL, DbType.String )
			};
			return new TableDescription( "Flytjandi", columns );
		}
	}

	public class FlytjandiSorter : IComparer<Flytjandi>
	{
		#region Member variables
		private String m_strOrderBy;
		#endregion

		#region Constructors
		public FlytjandiSorter(String strOrderBy)
		{
			m_strOrderBy = strOrderBy;
		}
		#endregion

		#region IComparer implementation
		public int Compare(Flytjandi x, Flytjandi y)
		{
			switch (m_strOrderBy)
			{
				case "Name":
					return x.Name.CompareTo(y.Name);
				case "Description":
					return x.Description.CompareTo(y.Description);
				case "Picture":
					return x.Picture.CompareTo(y.Picture);
				case "URL":
					return x.URL.CompareTo(y.URL);
			}

			return 0;
		}
		#endregion
	}

	public class FlytjandiCollection : DataList<Flytjandi>
	{
		#region Public functions
		public void Sort(String strOrderBy)
		{
			FlytjandiSorter sorter = new FlytjandiSorter(strOrderBy);
			base.Sort(sorter);
		}
		#endregion	
	}
}
